<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

/**
 * Get an url from a page id and lang
 *
 * @param integer docId
 * @param string lang - optionnal
 * 
 * @example {pageUrl docId=12 lang="FR"}
 */
function smarty_function_pageUrl($params, &$smarty)
{ 
	if(!isset($params["lang"]))
	{
		$lang = f_core_Context::getInstance()->getLang();
	}
	else
	{
		$lang = $params["lang"];
	}
	
	$document = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Page', $params['docId'], $lang);
	
	if(is_object($document))
	{
		if(method_exists($document, "getUrl"))
		{
			$url = URL_RELATIVE.$document->getUrl();

            if(isset($params["getId"]) && $params["getId"] == true)
            {
                $url .= "/".$document->getUniqueId();
            }

            return $url;
		}		
	}
	
	return "#";
}